<?php
session_start();
session_destroy();
?>
<html>
<?php include('include.header_admin.html'); ?>
<body class="bodyadmin">
	<form id="frm_bp" name="frm_bp">
	<div align="center">
	<div id="DATO_HIDE" style="display:none" style="width:90%">
	<div id="DATO"></div>
	</div>
	<br>
	<br>
	<br>
	<table> 
		<tr>
			<td>
			<img src='images/menu/logo-bonitos-int.png'>
			</td>
		</tr>
		<tr>
			<td>
			<p class="mensajes">Sistema de administraci&oacute;n</p>
			</td>
		</tr>
	</table>
		<br>
		<br>
	<table class='formulario'>
		<tr>
			<td>
			Usuario   
			</td>
			<td>
			<input type="text" id="usuario" name="usuario" class="validate['required']">
			</td>
		</tr>
		<tr>
			<td>
			Password  
			</td>
			<td>
			<input type="password" id="clave" name="clave" class="validate['required']">
			</td>
		</tr>
		<tr>
			<td>
			&nbsp;
			</td>
			<td>
			<input type="submit" name="submit" id="submit" value="Ingresar">
			</td>
		</tr>
	</table>
</div>
</form>
<div id="menu"></div>
</body>
 <?php include('include.footer_admin.html'); ?>
    <script>
///////////////////////////////
    var myCheck;
	myCheck = new FormCheck('frm_bp', {
	  submit:false,
		display:{
			errorsLocation : 1,
			indicateErrors : 2,
			keepFocusOnError : 0,
			closeTipsButton : 1,
			checkValueIfEmpty:1,                
			showErrors : 1
		}
	});		 
 
    $('frm_bp').addEvent('submit',function(ev){
        var IsValid;
       IsValid=myCheck.isFormValid();                                                                          
        if (IsValid){ 
            
             Ejecutor();
        }    
    });
///////////////////////////////
    function Ejecutor(){        
        window.addEvent('domready', function() {      	       
    		var req = new Request.JSON({
                method: 'POST',
                url: 'ajax/ajax_autenticar.php', 
                data: $('frm_bp'),                
                noCache:true,                     
                onRequest: function(){
                   $('DATO_HIDE').show();
                   $('submit').disabled = true;
                   $('DATO').innerHTML = 'Autenticando ...'; 
                },
                onComplete: function(){
                    setTimeout(function(){
                        $('DATO_HIDE').fade('out').get('tween').chain(function() {
                            $('DATO_HIDE').hide();
                            $('DATO_HIDE').fade('in');                                                         
                        });
                    },2000);                                                                                                                                                                                                              
                },             
                onSuccess: function(response){
                    switch(parseInt(response.RESULT)){
                        case 0:
                            $('DATO').innerHTML = "Acceso permitido";  
                            window.location='index_admin.php';
                            break;
                        case 1:
                            $('DATO').innerHTML = response.ERROR;
                            $('submit').disabled = false;
                            break;
                    }
                }
            }).post();        
       });
    }
    </script>
</html>
